﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Scrat.Core.Server
{
    public class TCPFileStreamClient
    {
        private static TCPFileStreamClient _instance;

        private TcpClient _client;

        public List<TcpClient> Clients { get; }

        private TCPFileStreamClient()
        {
            Clients = new List<TcpClient>();

            _client = new TcpClient();
            _client.ReceiveTimeout = 5000;
        }

        public static TCPFileStreamClient GetInstance()
        {
            if (_instance == null)
            {
                _instance = new TCPFileStreamClient();
            }
            return _instance;
        }

        public async Task<Stream> ConnectedAndRecFileStream(IPAddress address, int port)
        {
            await _client.ConnectAsync(address, port);
            return _client.GetStream();
        }

        /*public async void StartAndSendStream(IPAddress ipAddress, int port,
            Stream fStream)
        {
            await _client.ConnectAsync(ipAddress, port)
                .ContinueWith((pre) =>
                {
                    NetworkStream nStream  = _client.GetStream();
                    nStream.CopyToAsync(fStream);
                });
        }*/
    }
}
